//
//  DressUpView.m
//  ProfilePicture
//
//  Created by 张云江 on 2019/10/16.
//  Copyright © 2019年 张云江. All rights reserved.
//

#import "DressUpView.h"

@interface DressUpView ()
{
    NSMutableArray *arr_M1;
    NSMutableArray *cusArr;
    
    UIScrollView *dressUpScroll1;
    UIScrollView *dressUpScroll2;
    UIScrollView *dressUpScroll3;
}
@end

@implementation DressUpView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        arr_M1 = [NSMutableArray array];
        
        [self creatUI];
    }
    return self;
}

- (void)creatUI
{
    CustomBtn *cusBtn = [[CustomBtn alloc]init];
    cusBtn.tag = 100;
    [cusBtn setCustomBtnwtihNormal:@"mf_likeBeauty_1" withSelected:@"" withLabel:@"无正装"];
    [cusBtn addTarget:self action:@selector(onToBtnDressUpScroll1Click:) forControlEvents:UIControlEventTouchUpInside];
    cusBtn.backgroundColor = kUIColorFromRGA(0xF3F5FF, 1);
    [self addSubview:cusBtn];
    [cusBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(kRatio(20));
        make.top.mas_equalTo(kRatio(61));
        make.width.mas_equalTo(kRatio(52));
        make.height.mas_equalTo(kRatio(64));
    }];
    [arr_M1 addObject:cusBtn];
    
    NSArray *arr = @[@"女装",@"童装",@"男装"];
    cusArr = [NSMutableArray array];
    for (int i = 0; i < 3; i++) {
        CustomBtn *cusBtn = [[CustomBtn alloc]init];
        cusBtn.tag = i;
        [cusBtn addTarget:self action:@selector(onToBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [cusBtn setCustom3withLabel:arr[i]];
        if (i == 0) {
            [cusBtn setCustomSelected:YES];
        }
        [self addSubview:cusBtn];
        [cusArr addObject:cusBtn];
    }
    [cusArr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:kRatio(30) leadSpacing:kRatio(80) tailSpacing:kRatio(80)];
    
    [cusArr mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.height.mas_equalTo(kRatio(40));
    }];
    
    dressUpScroll1 = [[UIScrollView alloc]initWithFrame:CGRectMake(kRatio(72), kRatio(61), kScreenWidth - kRatio(72) - kRatio(20), kRatio(64))];
    dressUpScroll1.userInteractionEnabled = YES;
    dressUpScroll1.showsHorizontalScrollIndicator = NO;
    [self addSubview:dressUpScroll1];
    
    NSArray *titleArr = @[@"女装1",@"女装2",@"女装3",@"女装4",@"女装5",@"女装6"];
    NSArray *titleArr1 = @[@"https://leqi-public.oss-cn-shanghai.aliyuncs.com/wechat_applet/clothes/applet_girl1%403x.png",
                           @"https://leqi-public.oss-cn-shanghai.aliyuncs.com/wechat_applet/clothes/applet_girl2%403x.png",
                           @"https://leqi-public.oss-cn-shanghai.aliyuncs.com/wechat_applet/clothes/applet_girl3%403x.png",
                           @"https://leqi-public.oss-cn-shanghai.aliyuncs.com/wechat_applet/clothes/applet_girl4%403x.png",
                           @"https://leqi-public.oss-cn-shanghai.aliyuncs.com/wechat_applet/clothes/applet_girl5%403x.png",
                           @"https://leqi-public.oss-cn-shanghai.aliyuncs.com/wechat_applet/clothes/applet_girl6%403x.png"];
    
    for (int i = 0; i < 6; i++) {
        
        CustomBtn *cuBtn = [[CustomBtn alloc]init];
        cuBtn.tag = i;
        [cuBtn setCustom4BtnwtihNormal:titleArr1[i] withLabel:titleArr[i]];
        [cuBtn addTarget:self action:@selector(onToBtnDressUpScroll1Click:) forControlEvents:UIControlEventTouchUpInside];
        [dressUpScroll1 addSubview:cuBtn];
        [cuBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self->dressUpScroll1.mas_left).offset(kRatio(15 + (52 + 15) * i));
            make.top.equalTo(self->dressUpScroll1.mas_top);
            make.width.mas_equalTo(kRatio(52));
            make.height.mas_equalTo(kRatio(64));
        }];
        [arr_M1 addObject:cuBtn];
        
    }
    
    dressUpScroll1.contentSize = CGSizeMake(kRatio((52 + 15) * 6 + 20), 0);
    
    
    dressUpScroll2 = [[UIScrollView alloc]initWithFrame:CGRectMake(kRatio(72), kRatio(61), kScreenWidth - kRatio(72) - kRatio(20), kRatio(64))];
    dressUpScroll2.hidden = YES;
    dressUpScroll2.userInteractionEnabled = YES;
    dressUpScroll2.showsHorizontalScrollIndicator = NO;
    [self addSubview:dressUpScroll2];
    
    NSArray *titleArr2 = @[@"童装1",@"童装2",@"童装3",@"童装4"];
    NSArray *titleArr3 = @[@"https://leqi-public.oss-cn-shanghai.aliyuncs.com/wechat_applet/clothes/applet_kid1%403x.png",
                           @"https://leqi-public.oss-cn-shanghai.aliyuncs.com/wechat_applet/clothes/applet_kid2%403x.png",
                           @"https://leqi-public.oss-cn-shanghai.aliyuncs.com/wechat_applet/clothes/applet_kid3%403x.png",
                           @"https://leqi-public.oss-cn-shanghai.aliyuncs.com/wechat_applet/clothes/applet_kid4%403x.png"];
    
    for (int i = 0; i < 4; i++) {
        CustomBtn *cuBtn = [[CustomBtn alloc]init];
        cuBtn.tag = 10 + i;
        [cuBtn setCustom4BtnwtihNormal:titleArr3[i] withLabel:titleArr2[i]];
        [cuBtn addTarget:self action:@selector(onToBtnDressUpScroll1Click:) forControlEvents:UIControlEventTouchUpInside];
        [dressUpScroll2 addSubview:cuBtn];
        [cuBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self->dressUpScroll2.mas_left).offset(kRatio(15 + (52 + 15) * i));
            make.top.equalTo(self->dressUpScroll2.mas_top);
            make.width.mas_equalTo(kRatio(52));
            make.height.mas_equalTo(kRatio(64));
        }];
        [arr_M1 addObject:cuBtn];
        
    }
    dressUpScroll2.contentSize = CGSizeMake(kRatio((52 + 15) * 4 + 20), 0);
    
    
    dressUpScroll3 = [[UIScrollView alloc]initWithFrame:CGRectMake(kRatio(72), kRatio(61), kScreenWidth - kRatio(72) - kRatio(20), kRatio(64))];
    dressUpScroll3.hidden = YES;
    dressUpScroll3.userInteractionEnabled = YES;
    dressUpScroll3.showsHorizontalScrollIndicator = NO;
    [self addSubview:dressUpScroll3];
    
    NSArray *titleArr4 = @[@"男装1",@"男装2",@"男装3",@"男装4"];
    NSArray *titleArr5 = @[@"https://leqi-public.oss-cn-shanghai.aliyuncs.com/wechat_applet/clothes/applet_boy1%403x.png",
                           @"https://leqi-public.oss-cn-shanghai.aliyuncs.com/wechat_applet/clothes/applet_boy2%403x.png",
                           @"https://leqi-public.oss-cn-shanghai.aliyuncs.com/wechat_applet/clothes/applet_boy3%403x.png",
                           @"https://leqi-public.oss-cn-shanghai.aliyuncs.com/wechat_applet/clothes/applet_boy4%403x.png"];
    
    for (int i = 0; i < 4; i++) {
        CustomBtn *cuBtn = [[CustomBtn alloc]init];
        cuBtn.tag = 20 + i;
        [cuBtn setCustom4BtnwtihNormal:titleArr5[i] withLabel:titleArr4[i]];
        [cuBtn addTarget:self action:@selector(onToBtnDressUpScroll1Click:) forControlEvents:UIControlEventTouchUpInside];
        [dressUpScroll3 addSubview:cuBtn];
        [cuBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self->dressUpScroll3.mas_left).offset(kRatio(15 + (52 + 15) * i));
            make.top.equalTo(self->dressUpScroll3.mas_top);
            make.width.mas_equalTo(kRatio(52));
            make.height.mas_equalTo(kRatio(64));
        }];
        [arr_M1 addObject:cuBtn];
        
    }
    dressUpScroll3.contentSize = CGSizeMake(kRatio((52 + 15) * 4 + 20), 0);
    
}

- (void)onToBtnClick:(CustomBtn *)btn
{
    for (CustomBtn *cbtn in cusArr) {
        [cbtn setCustomSelected:NO];
    }
    [btn setCustomSelected:YES];
    
    switch (btn.tag) {
        case 0:
        {
            dressUpScroll1.hidden = NO;
            dressUpScroll2.hidden = YES;
            dressUpScroll3.hidden = YES;
        }
            break;
        case 1:
        {
            dressUpScroll1.hidden = YES;
            dressUpScroll2.hidden = NO;
            dressUpScroll3.hidden = YES;
        }
            break;
        case 2:
        {
            dressUpScroll1.hidden = YES;
            dressUpScroll2.hidden = YES;
            dressUpScroll3.hidden = NO;
        }
            break;
            
        default:
            break;
    }
}

- (void)onToBtnDressUpScroll1Click:(CustomBtn *)btn
{
    for (CustomBtn *cbtn in arr_M1) {
        [cbtn setCustomStyeSelected:NO];
    }
    [btn setCustomStyeSelected:YES];
    
    NSString *dress = @"applet_girl1";
    switch (btn.tag) {
        case 0:
        {
            dress = @"applet_girl1";
        }
            break;
        case 1:
        {
            dress = @"applet_girl2";
        }
            break;
        case 2:
        {
            dress = @"applet_girl3";
        }
            break;
        case 3:
        {
            dress = @"applet_girl4";
        }
            break;
        case 4:
        {
            dress = @"applet_girl5";
        }
            break;
        case 5:
        {
            dress = @"applet_girl6";
        }
            break;
        case 10:
        {
            dress = @"applet_kid1";
        }
            break;
        case 11:
        {
            dress = @"applet_kid2";
        }
            break;
        case 12:
        {
            dress = @"applet_kid3";
        }
            break;
        case 13:
        {
            dress = @"applet_kid4";
        }
            break;
        case 20:
        {
            dress = @"applet_boy1";
        }
            break;
        case 21:
        {
            dress = @"applet_boy2";
        }
            break;
        case 22:
        {
            dress = @"applet_boy3";
        }
            break;
        case 23:
        {
            dress = @"applet_boy4";
        }
            break;
        case 100:
        {
            dress = @"";
        }
            break;
        default:
            break;
    }
    WCDelegate.currClothes = dress;
    self.DressUpClick(dress);
}
@end
